<template>
	<view class="pet">
		<view class="top-info" ref="topInfo" :style="{'background-image': `url(${'data:image/jpg;base64,'+avatarUrl})`}" @click="topInfoClick" >
			<view class="bg-mask">
			</view>
			<button class="my-info avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<!--  -->
				<!-- https://pic2.zhimg.com/80/v2-4dbd9490f32cfe8fcc8a379a97593d69_720w.webp -->
				<image class="avatar" :src="'data:image/jpg;base64,'+avatarUrl"></image>
				<view class="user-name">
					<text class="name" v-if="loginStatus">{{username}}</text>
					<text class="name" v-if="!loginStatus">未登录</text>
				</view>
			</button>
			<view class="sign">
				<text>这个人很懒什么都没有留下</text>
			</view>
			<view class="num-msg">
				<view class="fouc item">
					<text class="num">0</text>
					<text class="text">关注</text>
				</view>
				<view class="fans item">
					<text class="num">0</text>
					<text class="text">粉丝</text>
				</view>
				<view class="moment item">
					<text class="num">0</text>
					<text class="text">文章</text>
				</view>
			</view>
			<button class="set-account">账户设置</button>
		</view>
		<view class="title">宠物列表</view>
		<view class="my-pet-list">
			<block v-for="(item, index) in petList" :key="index">
				<view class="item">
					<view class="avatar-wrap">
						<image class="avatar" :src="item.photo" mode="aspectFill"></image>
					</view>
					<view class="item-info">
						<view class="first">
							<text class="name">gigibanbddddddd</text>
							<image class="boy" v-if="item.gender == 1" src="@/static/images/common/boy.png"></image>
							<image class="gril" v-if="item.gender == 2" src="@/static/images/common/girl.png"></image>
						</view>
						
						<text class="kind">{{item.kind}}</text>
						<view class="weight">{{item.weight}}</view>
					</view>
				</view>
			</block>
		</view>
		<view class="func-menu">
			<li class="item">
				<image class="img" src="@/static/images/index/note.png" mode="aspectFit"></image>
				<text class="text">记录</text>
			</li>
			<li class="item" @click="addPetClick">
				<image class="img" src="@/static/images/index/add_pet.png" mode="aspectFit"></image>
				<text class="text">添宠</text>
			</li>
		</view>
	</view>
</template>

<script>
	import { isLogin } from '@/utils/tools.js'
	import unLoginImg from '@/static/images/common/unlogin.png'
	import { addPetRequest } from '@/service/pets/pet.js'
	import storage  from '@/utils/storage.js'
	import imageToBase64 from '@/utils/imageToBase64.js'
	import { base64FileHeaderMapper } from '@/utils/tools.js'
	export default {
		components: {
		},
		data() {
			return {
				back: {
					show: false
				},
				imgbase64: '',
				avatarUrl: '',
				username: '',
				unLoginImg: unLoginImg,
				topHeight: 0,
				topBackgroundColor: '#fff',
				topMainBackGroundColor: '#fff',
				loginStatus: false,
				petList: [
					{
						id: 1,
						name: '阿旺',
						gender: 1,
						photo: 'https://pic1.zhimg.com/80/v2-667581b39a456de7190bd629ef936918_720w.webp',
						weight: '2kg',
						kind: '拉布拉多'
					},
					{
						id: 2,
						name: '旺财',
						gender: 2,
						photo: 'https://bkimg.cdn.bcebos.com/pic/faedab64034f78f0f736a529aa7e1d55b319eac4b690?x-bce-process=image/resize,m_lfit,w_220,limit_1',
						weight: '2kg',
						kind: '加菲猫'
					},
					{
						id: 3,
						name: '迪迦',
						gender: 1,
						photo: 'https://pic4.zhimg.com/80/v2-6233ef684b7f8911b8a1b92664180f2b_720w.webp',
						weight: '2kg',
						kind: '泰迪'
					}
				]
			}
		},
		beforeMount() {
			this.setIshow()
			if(isLogin()) {
				let userInfo = storage.get('userInfo')
				this.avatarUrl = userInfo.avatar.replace(/[\r\n]/g, "");
				this.username = userInfo.username
			}
		},
		methods: {
			setTopBg() {
				
			},
			topInfoClick() {
				if(isLogin()) {
					console.log('登录了')
				} else {
					uni.navigateTo({
						url: '/subpages/login/loginView'
					})
					console.log('没有登录')
				}
			},
			async onChooseAvatar(e) {
				let tmpUrl = e.detail.avatarUrl
				let imgBasee64 = await imageToBase64(tmpUrl)
				this.avatarUrl = imgBasee64
				console.log('imabase', imgBasee64)
				this.$store.dispatch('login/updateUserInfo', {
					filed: 'avatar',
					newValue: imgBasee64
				})
			},

			onNickName(e) {
				console.log('e2',e)
			},

			weixinOauthByLogin() {
				uni.getUserProfile({
					desc: '获取用户信息~',
					success(res) {
						console.log(res)
					}
				})
			},
			setIshow() {
				if(isLogin()) {
					this.loginStatus = true
				} else {
					this.loginStatus = false
				}
			},
			addPetClick() {
				uni.navigateTo({
					url: '/pages/pets/cpns/addPet'
				})
				// let user_id = stroage.get('userInfo').userInfo.id
				// addPetRequest({
				// 	user_id: user_id,
				// 	name: '阿狗', 
				// 	age: 2, 
				// 	gender: '母', 
				// 	breed: '狗子', 
				// 	photo: 'https://ts1.cn.mm.bing.net/th/id/R-C.e4f328fd058a4a57d8c14af50b7653dd?rik=hm5QKFyFYSksZQ&riu=http%3a%2f%2fa3.att.hudong.com%2f55%2f88%2f19300001290790130897880566904_950.jpg&ehk=%2bYhJdl7ztQv16gdf2WBuEKs%2fnNHMhxOC2iuRV9QRN%2bo%3d&risl=&pid=ImgRaw&r=0',
				// 	vaccine: '',
				// 	weight: 2.221, 
				// 	description: '没什么说的121212'
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/  .ljs-top .top .topMain {
		padding-bottom: 0;
	}
	.top-info {
		position: relative;
		height: 500rpx;
		// background-image: url('https://pic2.zhimg.com/80/v2-4dbd9490f32cfe8fcc8a379a97593d69_720w.webp');
		background-position: center;
		z-index: 0;
		padding-top: 80rpx;
		padding-left: 20px;
		color: #fff;
		border-bottom-left-radius: 90% 8%;
		border-bottom-right-radius: 90% 8%;
		background-size: cover;
		overflow: hidden;
	}
	
	.bg-mask {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: rgba(0, 0, 0, .5);
		z-index: -2;
	}
	
	.my-info {
		display: flex;
		align-items: center;
		color: #fff;
	}
	
	.my-info .avatar {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
		overflow: hidden;
	}
	
	.my-info .user-name {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 120rpx;
		margin-left: 8px;
		color: #fff;
	}
	
	.my-info .user-name {
		font-size: 18px;
	}
	
	.set-account {
		height: 20px;
		width: 75px;
		align-self: flex-end;
		margin-right: 20rpx;
		text-align: center;
		font-size: 10px;
		line-height: 20px;
		border-radius: 10px;
		background-color: rgba(220, 220, 220, 0.5);
	}
	
	.publish-time {
		font-size: 14px;
	}
	
	.sign {
		font-size: 12px;
		margin-top: 20px;
	}
	
	.num-msg {
		display: flex;
		margin-top: 60rpx;
	}
	
	.num-msg .item {
		display: flex;
		// width: 80px;
		margin-right: 40px;
		flex-direction: column;
		text-align: center;
	}
	
	.num-msg .item .text {
		margin-top: 6px;
		font-size: 12px;
	}
	
	.my-pet-list {
		display: flex;
		padding: 0 20rpx;
		margin-top: 6px;
		border-top: 1px #eee solid;
		overflow-x: scroll;
	}
	
	.title {
		padding-left: 20rpx;
		margin-top: 10px;
		font-weight: 600;
	}
	
	.my-pet-list .item {
		display: flex;
		align-items: center;
		// width: 150px;
		height: 100px;
		color: #fff;
	}
	
	.my-pet-list .item .avatar-wrap {
		width: 60px;
		height: 60px;
	}
	
	.my-pet-list .avatar {
		width: 60px;
		height: 60px;
		border-radius: 50%;
		overflow: hidden;
	}
	
	.my-pet-list .item-info {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 60px;
		margin-left: 8px;
		color: #000;
	}
	
	.my-pet-list .first {
		display: flex;
	}
	
	.my-pet-list .name {
		position: relative;
		max-width: 60px;
		overflow:hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		-o-text-overflow:ellipsis;
		font-size: 14px;
	}
	
	.my-pet-list .boy {
		width: 20px;
		height: 20px;
		margin-left: 5px;
		background-image: url('@/static/images/common/boy.png');
	}
	
	.my-pet-list .gril {
		width: 20px;
		height: 20px;
		margin-left: 5px;
		background-image: url('@/static/images/common/girl.png');
	}
	
	.my-pet-list .gender {
		width: 20px;
		height: 20px;
	}
	
	.my-pet-list .kind,
	.my-pet-list .weight {
		font-size: 12px;
		color: #bfbec0;
	}
	
	.my-pet-list .weight {
		width: 40px;
		height: 18px;
		line-height: 18px;
		text-align: center;
		background-color: #87d3b1;
		color: #fff;
		border-radius: 6px;
	}
	
	.func-menu {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-evenly;
		width: 100%;
		margin: 20px auto 0;
	}
	
	.func-menu .item {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 25%;
		margin-bottom: 30px;
	}
	
	.func-menu .item .text {
		margin-top: 10px;
	}
	
	.func-menu .item .img {
		width: 50px;
		height: 50px;
		display: block;
	}
	.avatar-wrapper {
		background: (0,0,0,.0);
		border: 1px transparent solid;
		border-radius: 0;
		background-color: transparent;
	}
	.avatar-wrapper::after {
		border: none;
	}
</style>